let indexModel = require('../model/indexModel');
let moment = require('moment');
module.exports = {
    showIndexPage(req, res) {
        let pagesize = 10
        let nowPage = req.query.page || 1
        indexModel.getArticles(pagesize, nowPage, (err, results) => {
            results[0].forEach(item => {
                item.ctime = moment(item.ctime).fromNow()
            })
            let totalPage = Math.ceil(results[1][0].totalCount / pagesize)
            res.render('index', {
                isLogin: req.session.isLogin,
                user: req.session.user,
                list: results[0],
                totalPage: totalPage,
                nowPage: parseInt(nowPage)
              })
            
        })
    }
}